package com.d2.common.domain;

import lombok.Data;

@Data
public class Result<T> {
    private int code = 0;
    private String msg = "成功";
    private T data;

    public Result() {

    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> Result<T> success() {
        return new Result<>();
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setData(data);
        return result;
    }

    public static <T> Result<T> success(T data, String msg) {
        Result<T> result = new Result<>();
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(String s) {
        Result<T> result = new Result<>();
        result.setCode(-1);
        result.setMsg(s);
        return result;
    }

    public static <T> Result<T> error() {
        Result<T> result = new Result<>();
        result.setCode(-1);
        result.setMsg("服务器内部错误");
        return result;
    }
}
